
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.*;

import org.w3c.dom.Document;

import com.facebook.api.*;


/**
 * Servlet implementation class for Servlet: FacebookServlet
 *
 */
 public class FacebookServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
   static final long serialVersionUID = 1L;
   protected static final String FB_APP_URL =
	   "http://apps.facebook.com/test_graphes/";
   
   protected static final String FB_SERVER_URL =
	   "  http://localhost:8080/test_graphes/";

   protected static final String FB_APP_ADD_URL =
	      "http://www.facebook.com/add.php?api_key=";

   protected static final String FB_API_KEY =
	      "05ecf80aecb4a15c09ca9234d6cd5b47";

   private static final String FB_SECRET_KEY =
	      "3817b6ce887afcd8d68fd0cdd8fcbc49";
   
   protected static final String FB_APP_NAME =
	      "test_graphes";

    /* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public FacebookServlet() {
		super();
	}   	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}  	
	
	/* (non-Java-doc)
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}   
	
	/*
	    * This method is used by all of the application's servlets
	    * (or  web framework actions) to authenticate the app with
	    * Facebook.
	    */
	   protected FacebookRestClient getAuthenticatedFacebookClient(
	         HttpServletRequest request, HttpServletResponse response)
	   {
		  Facebook fb = new Facebook(request, response,FB_API_KEY, FB_SECRET_KEY);
	      String next = request.getServletPath().substring(1);

	      if (fb.requireLogin(next)) return null;

	      return fb.getFacebookRestClient();
	   }
	   
	   static public FacebookRestClient getAuthenticatedFacebookClient(String sessionKey){
		   
		   FacebookRestClient fb = new FacebookRestClient(FB_API_KEY, FB_SECRET_KEY, sessionKey);
		   return fb;
		   
	   }

}